﻿namespace Hotel.Web.Models
{
    using System;
    using System.ComponentModel.DataAnnotations;
    using System.Xml.Serialization;
    using Hotel.Model.Infrastructure;
    using Hotel.Module.Resources.Models;
    using HotelManagment = Hotel.Module.Management.Models;

    public class RoomOrder : IAssignable
    {
        public int ID { get; set; }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Display(ResourceType = typeof(Hotel.Web.Views.OrderRoom.RoomOrder), Name = "InDate")]
        [DataType(DataType.Date)]
        [XmlAttribute(typeof(DateTime))]
        public DateTime InDate { get; set; }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Display(ResourceType = typeof(Hotel.Web.Views.OrderRoom.RoomOrder), Name = "OutDate")]
        [DataType(DataType.Date)]
        [XmlAttribute(typeof(DateTime))]
        public DateTime OutDate { get; set; }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Display(ResourceType = typeof(Hotel.Web.Views.OrderRoom.RoomOrder), Name = "ItemType")]
        public string RoomType { get; set; }

        // look class ContactInfo
        public ContactInfo ContactInformation { get; set; }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Range(1, 50, ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "NumberOfPeopleErrorMessage")] 
        [Display(ResourceType = typeof(Hotel.Web.Views.OrderRoom.RoomOrder), Name = "NumberOfPeople")]
        public int NumberOfPeople { get; set; }

        [Required(ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "RequiredErrorMessage")]
        [Range(1, 15, ErrorMessageResourceType = typeof(Hotel.Web.Views.Shared.Validation), ErrorMessageResourceName = "NumberOfRoomsErrorMessage")]
        [Display(ResourceType = typeof(Hotel.Web.Views.OrderRoom.RoomOrder), Name = "RoomNum")]
        public int RoomNum { get; set; }

        public void AssignTo(object obj)
        {
            if (obj is HotelManagment.Order)
            {
                HotelManagment.Order modelOrder = obj as HotelManagment.Order;
                modelOrder.Email = ContactInformation.Contacts.EMail;
                modelOrder.Phone = ContactInformation.Contacts.Phone;
                modelOrder.FName = ContactInformation.FName;
                modelOrder.LName = ContactInformation.LName;

                if (RoomType == Hotel.Web.Views.OrderRoom.RoomOrder.Standart)
                {
                    modelOrder.RoomType = HotelManagment.ItemTypes.StandartRoom;
                }
                else if (RoomType == Hotel.Web.Views.OrderRoom.RoomOrder.SemiSuit)
                {
                    modelOrder.RoomType = HotelManagment.ItemTypes.SemiSuit;
                }
                else if (RoomType == Hotel.Web.Views.OrderRoom.RoomOrder.Suit)
                {
                    modelOrder.RoomType = HotelManagment.ItemTypes.Suit;
                }
                else
                {
                    modelOrder.RoomType = HotelManagment.ItemTypes.StandartRoom;
                }

                modelOrder.NumberOfRooms = RoomNum;
                modelOrder.NumberOfPeople = NumberOfPeople;
                modelOrder.InDate = InDate.Date;
                modelOrder.OutDate = OutDate.Date;
                return;
            }

            if (obj is Period)
            {
                Period period = obj as Period;
                period.InDate = InDate;
                period.OutDate = OutDate;
                return;
            }

            throw new NotSupportedException();
        }
    }
}